package jdbc.homework;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Scanner;

public class SignDemo {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        System.out.println("输入用户名");
        String username=scan.nextLine();
        System.out.println("输入密码");
        String password=scan.nextLine();
        System.out.println("输入昵称");
        String nickname=scan.nextLine();
        System.out.println("输入年龄");
        int age=scan.nextInt();
        try (Connection connection= DBUtil1.getConnecting()){

            String aql="INSERT INTO user1 (username,password,nickname,age) "+
                    "VALUES(?,?,?,?) ";
            PreparedStatement ps=connection.prepareStatement(aql);
            ps.setString(1,username);
            ps.setString(2,password);
            ps.setString(3,nickname);
            ps.setInt(4,age);
            int num=ps.executeUpdate();
            System.out.println(num>0?"注册成功":"注册失败");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
